<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue refs</title>
    <script src="./js/vue.js"></script>
</head>

<body>
    <div id="app">
      <h1 ref="h1">{{message}}</h1>  
      
      <template v-for="(item ,index) in arr">
        <div ref="divs">{{item}}</div>
      </template>  
    </div>

</body>
<script>
    /**
       this.$data
       this.$watch
       this.$el
       this.$set
       this.$options
       this.nextTick
       this.refs 
    */

    var vm = new Vue({
        el: '#app',
        data: {
            message: 'Hello Vue!',
            arr: [1,2,3]
        },
        mounted: function(){
            // 如果不是通过v-for,则只能获取第一个
            console.log(this.$refs.h1);
            
            console.log(this.$refs.divs);

            this.arr = [1,2,3,4];

            console.log(this.$refs.divs);
            // 异步方法: 等待渲染dom结束执行
            this.$nextTick(()=>{
                console.log(this.$refs.divs);
            })
        },
    })
   


</script>

</html>